Skip to content

Api for metadata#1199

Merged
Strift merged 14 commits intomeilisearch:mainfrom
awais786:api-for-metadata
Mar 11, 2026
Merged

Api for metadata#1199
Strift merged 14 commits intomeilisearch:mainfrom
awais786:api-for-metadata

Conversation

@awais786
Copy link
Contributor

@awais786 awais786 commented Jan 21, 2026

#1198

Implements support for the new POST /indexes/{indexUid}/fields endpoint introduced in Meilisearch v1.33.0.

Description

This PR adds the get_fields() method to the Index class, which returns detailed metadata about all fields in an index. The endpoint provides comprehensive information about each field's configuration, including display, search, filtering, sorting, ranking rules, and localization settings.

Summary by CodeRabbit

  • New Features

    • Retrieve detailed index field metadata (name, searchable, filterable, sortable) via a new API method. Supports optional filtering and offset/limit pagination and returns structured per-field metadata.
  • Tests

    • Added tests verifying metadata retrieval, configuration-driven visibility changes, filtering behavior, and pagination.

Usage of AI.

I use cursor for coding help but did manual changes and also did testing locally.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new API path token fields and a public Index.get_fields(...) method that POSTs to the index fields endpoint to retrieve field metadata. Four tests were added to validate retrieval, settings reflection, filtering, and pagination.

Changes

Cohort / File(s) Summary
API Path Constant
meilisearch/config.py
Added fields = "fields" to Config.Paths.
Index API Implementation
meilisearch/index.py
Added Index.get_fields(offset: Optional[int]=None, limit: Optional[int]=None, filter: Optional[MutableMapping[str, Any]]=None) -> List[Dict[str, Any]] which POSTs to /indexes/{uid}/fields and returns per-field metadata.
Tests
tests/index/test_index.py
Added tests: test_get_fields, test_get_fields_with_configurations, test_get_fields_with_filter, test_get_fields_with_pagination to verify retrieval, config reflection, filtering, and pagination.

Sequence Diagram(s)

sequenceDiagram
  participant Test as Test/Client
  participant Index as Index.get_fields()
  participant HTTP as HTTP Client
  participant Server as Meilisearch Server

  Test->>Index: call get_fields(offset?, limit?, filter?)
  Index->>HTTP: POST /indexes/{uid}/fields with body {offset, limit, filter}
  HTTP->>Server: forward request
  Server-->>HTTP: 200 OK + JSON list of field metadata
  HTTP-->>Index: response payload
  Index-->>Test: return List[Dict[str, Any]]
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I found a new path called "fields" today,
I hopped, I posted, then I ran away.
Metadata danced in pages and rows,
Filters and limits where the rabbit goes.
Tests cheered softly as the new endpoint glows. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Api for metadata' is vague and generic, failing to clearly describe the specific change being implemented. Use a more specific title such as 'Add get_fields() method to retrieve field metadata' or 'Implement fields endpoint API support' to clearly convey the primary change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@meilisearch/index.py`:
- Around line 2608-2610: Remove the trailing whitespace after the statement that
initializes the request body (the line "body: Dict[str, Any] = {}") so the file
no longer contains an extra space at end-of-line; update the block around the
body/offset handling (the code referencing the variable body and the subsequent
if offset is not None) to ensure there are no trailing spaces on any lines.
- Around line 2553-2558: The parameter name 'filter' in get_fields is shadowing
the built-in and triggers pylint W0622; rename the parameter (e.g., to filter_
or filters) and update all internal references within the get_fields function
signature and body to the new name (preserving type Optional[MutableMapping[str,
Any]] and behavior), or if you prefer consistency with nearby methods add the
same local pylint disable used elsewhere instead of renaming; ensure only
get_fields and its internals are changed so the API remains non-breaking.

In `@tests/index/test_index.py`:
- Around line 350-371: The failing linter is due to trailing whitespace in the
new test block that exercises index.get_fields (variables: page1, page2,
limited); open the test_index.py test that contains the pagination assertions
for index.get_fields and remove any trailing spaces at the ends of the affected
lines (the lines with the page1/page2/limited assertions and surrounding
comments) so there are no trailing whitespace characters left, then save and
re-run linting.

@Strift Strift added the enhancement New feature or request label Mar 4, 2026
@Strift Strift added this pull request to the merge queue Mar 4, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 4, 2026
Copy link
Contributor

@Strift Strift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests failed when I added the PR to the merge queue, can you look into it?

@awais786
Copy link
Contributor Author

awais786 commented Mar 4, 2026

Yes, I will explore it today

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
meilisearch/index.py (1)

2562-2562: Prefer Mapping for filter since it is not mutated.

Using Mapping[str, Any] communicates read-only intent more accurately than MutableMapping[str, Any].

💡 Suggested diff
-        filter: Optional[MutableMapping[str, Any]] = None,  # pylint: disable=redefined-builtin
+        filter: Optional[Mapping[str, Any]] = None,  # pylint: disable=redefined-builtin
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@meilisearch/index.py` at line 2562, The parameter type for filter is declared
as Optional[MutableMapping[str, Any]] but the value is never mutated; change its
annotation to Optional[Mapping[str, Any]] to express read-only intent, update
any necessary imports to include Mapping from typing, and remove or adjust the
pylint disable comment if no longer needed; locate the parameter named "filter"
in meilisearch/index.py and replace MutableMapping with Mapping in that
function/method signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@meilisearch/index.py`:
- Line 2562: The parameter type for filter is declared as
Optional[MutableMapping[str, Any]] but the value is never mutated; change its
annotation to Optional[Mapping[str, Any]] to express read-only intent, update
any necessary imports to include Mapping from typing, and remove or adjust the
pylint disable comment if no longer needed; locate the parameter named "filter"
in meilisearch/index.py and replace MutableMapping with Mapping in that
function/method signature.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7de45a1e-16a6-4534-9c29-0c79e852fa06

📥 Commits

Reviewing files that changed from the base of the PR and between 41c8ac8 and 2c0a78b.

📒 Files selected for processing (3)
  • meilisearch/config.py
  • meilisearch/index.py
  • tests/index/test_index.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/index/test_index.py
  • meilisearch/config.py

@awais786 awais786 requested a review from Strift March 4, 2026 10:31
Copy link
Contributor

@Strift Strift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! Let's get this merged 🙌

@Strift Strift added this pull request to the merge queue Mar 11, 2026
Merged via the queue into meilisearch:main with commit d9f09e7 Mar 11, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants